/**
 * Created by jt on 2017/5/8.
 */
import "./index.less";
import "../../../unit/common/js/bootstrap_js/select2.min.js";
import "../../../unit/common/js/bootstrap_js/jquery.dataTables.js";
import "../../../unit/common/js/bootstrap_js/form-samples.js";
import "../../../unit/common/js/bootstrap_js/table-editable.js";

jQuery(function () {
    App.init();
    var token = sessionStorage.getItem('token');
    if (token == null || token =='') {
        location.href = HOST_FRT+'/expert_grid/login.html';
    }
    var projId = getArgs().id;
    var grdId;
    jQuery.ajax({
        url: HOST_ADDR+'/cpmp/bidProjOnMngForExpt/viewBidDtl/'+projId,
        type: 'get',
        // data: JSON.stringify(data),
        dataType: 'json',
        contentType:"application/json",
        headers: {
            'access_token': token,'login_type':'ums'
        },
        success: function(resp){
            if (!resp.success) {
                console.log(resp.msgCod+' '+resp.msgInf);
                return;
            }
            console.log(resp)
            var servPrms;
            if(resp.data.qotInf.servPrms != null && resp.data.qotInf.servPrms!='') {
                servPrms =resp.data.qotInf.servPrms;
            } else {
                servPrms='';
            }
            var qotMemo;
            if(resp.data.qotInf.qotMemo != null && resp.data.qotInf.qotMemo!='') {
                qotMemo =resp.data.qotInf.qotMemo;
            } else {
                qotMemo='';
            }
            if (resp.data.bidProjOnExptGrdDtl.scr != null && resp.data.bidProjOnExptGrdDtl.scr != '') {
                jQuery('.score').val(resp.data.bidProjOnExptGrdDtl.scr);
                jQuery('.scrMemo').val(resp.data.bidProjOnExptGrdDtl.scrMemo);
            }
            jQuery('.basicInfo').append('<div class="portlet-body"><table class="table table-striped table-bordered"><tbody><tr>' +
                '<td width="16%">承诺：</td><td colspan="5">'+servPrms+'</td><tr>' +
                '<tr><td width="16%">备注信息：</td><td colspan="5">'+qotMemo+'</td></tr></tbody></table></div>');

            for(var i = 0;i< resp.data.qotDtls.length;i++) {

                jQuery('.basicInfo').append('<div class="portlet-body"> <table class="table table-striped table-bordered"> <tbody> <tr> ' +
                    '<td width="16%">品目：</td><td width="32%">'+resp.data.qotDtls[i].matNam+'</td> ' +
                    '<td width="16%">供应数量：</td><td width="8%">'+resp.data.qotDtls[i].splNum+'</td> ' +
                    '<td width="16%">计量单位：</td><td width="8%">'+resp.data.qotDtls[i].matUnt+'</td></tr> <tr> ' +
                    '<td>报价：</td><td colspan="5">'+resp.data.qotDtls[i].untPri+'</td></tr></tbody>');
            }

            if (resp.data.qotInf2 != null && resp.data.qotInf2 != '') {
                var servPrms2;
                if(resp.data.qotInf2.servPrms != null && resp.data.qotInf2.servPrms!='') {
                    servPrms2 =resp.data.qotInf2.servPrms;
                } else {
                    servPrms2='';
                }
                var qotMemo2;
                if(resp.data.qotInf2.qotMemo != null && resp.data.qotInf2.qotMemo!='') {
                    qotMemo2 =resp.data.qotInf2.qotMemo;
                } else {
                    qotMemo2='';
                }
                jQuery('.basicInfo').after('<div class="portlet box blue basicInfo2"><div class="portlet-title">' +
                    '<div class="caption"><i class="icon-reorder"></i>二次报价信息</div><div class="tools">' +
                    '<a href="javascript:;" class="collapse"></a> </div></div>'+
                    '<div class="portlet-body"><table class="table table-striped table-bordered"><tbody><tr>' +
                    '<td width="16%">承诺：</td><td colspan="5">'+servPrms2+'</td><tr>' +
                    '<tr><td width="16%">备注信息：</td><td colspan="5">'+qotMemo2+'</td></tr></tbody></table></div></div>'
                );

                for (var i = 0;i< resp.data.qotDtls2.length;i++) {

                    jQuery('.basicInfo2').append('<div class="portlet-body"> <table class="table table-striped table-bordered"> <tbody> <tr> ' +
                        '<td width="16%">品目：</td><td width="32%">'+resp.data.qotDtls2[i].matNam+'</td> ' +
                        '<td width="16%">供应数量：</td><td width="8%">'+resp.data.qotDtls2[i].splNum+'</td> ' +
                        '<td width="16%">计量单位：</td><td width="8%">'+resp.data.qotDtls2[i].matUnt+'</td></tr> <tr> ' +
                        '<td>报价：</td><td colspan="5">'+resp.data.qotDtls2[i].untPri+'</td></tr></tbody>');
                }

            }

            grdId = resp.data.bidProjOnExptGrdDtl.grdId;
            //打分
            jQuery('.gridOk').click(function () {
                if (jQuery('.score').val() =='') {
                    alert('请打分！');
                    return;
                }
                var data = {
                    "id":projId,
                    "scr":jQuery('.score').val(),
                    "scrMemo":jQuery('.scrMemo').val()
                };
                jQuery.ajax({
                    url: HOST_ADDR+'/cpmp/bidProjOnMngForExpt/score',
                    type: 'post',
                    data: JSON.stringify(data),
                    dataType: 'json',
                    contentType:"application/json",
                    headers: {
                        'access_token': token,'login_type':'ums'
                    },
                    success: function(resp){
                        if (!resp.success) {
                            console.log(resp.msgCod+' '+resp.msgInf);
                            return;
                        }
                        // console.log(resp)
                        alert('打分成功！');
                        location.href = '/expert_grid/application_list.html?id='+grdId;

                    },
                    error:function(err){
                        console.log(err);
                    }
                });
            });

        },
        error:function(err){
            console.log(err);
        }
    });
});